package com.echo.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns={"/first","/first/*"})
public class Servlet extends HttpServlet{
     
	private static final long serialVersionUID = -5340775376372502716L;
		protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          doPost(request, response);
        }
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        	  request.setCharacterEncoding("utf-8"); 
//          	System.out.println(request.getContextPath());  
//          	System.out.println(request.getParameter("userName"));
//        	System.out.println(request.getParameter("pass"));
//        	System.out.println(request.getParameter("sex"));
        	String url = request.getRequestURI();
               if(url.endsWith("update")){
            	   System.out.println("------更新-------");
          Connection conn = ConnectionManager1.getInstance().getConnection();
           String sql="select * FROM school WHERE school_id=19;";                  
          try {
			PreparedStatement state = conn.prepareStatement(sql);
		    ResultSet rs = state.executeQuery();
		    ResultSetMetaData meta = rs.getMetaData();
			while(rs.next()){
			     for(int i=1;i<=meta.getColumnCount();i++){
				System.out.println(meta.getColumnLabel(i)+rs.getString(meta.getColumnLabel(i)));
				}
			}
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
               }
        }
}
